<%-- 
    Document   : HomePage
    Created on : 19-05-2011, 21:26:25
    Author     : ngloc_it
--%>

<%@page import="uit.jee.lib.utilities.SystemProperities"%>
<%@page import="uit.jee.lib.dto.BookDTO"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<%
    int numBook = 0;
    ArrayList<BookDTO> books = (ArrayList<BookDTO>) session.getAttribute("topbooks");
    if(books != null){
        numBook = books.size();
    }
    
    BookDTO book = (BookDTO) session.getAttribute("bookrandom");

%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script language="javascript" type="text/javascript" src="../js/javascriptfile.js"></script>
        <link rel="stylesheet" type="text/css" href="../css/style.css">

        <%--<script language="javascript" type="text/javascript" src="../js/Common.js"></script>--%>
        <title>Trang chủ</title>
    </head>
    <body>
      <div id="wrapper">
          <%@include file ="./subpage/menu.jsp" %>
          <%@include file ="./subpage/header.jsp" %>
          <div class="divider"></div>
         <%@include file ="./subpage/searchbar.jsp" %>

         <div id="orangerow">

             <%@include file="./subpage/navOrange.jsp" %>

             <div class="col">
                 <div id="bookmonth">

                      <b><i>Danh sách các sách trong danh mục</i></b>
                     <table width="412" >
                        <tr>
                            <%for(int i = 0; i < numBook-1; i++){
                                final BookDTO bookTemp = books.get(i);
                            %>
                                <td>
                                    <div style="border: 1px solid #d2ffc9; top:auto;">
                                        <img width="30px" height="30px" src="../images/picture_1.gif" alt="<%=bookTemp.getAuthor()%>"/>

                                    <p><%=bookTemp.getName()%></p>
                                    <p><%=bookTemp.getAuthor()%></p>
                                    <p><%=bookTemp.getPublisher()%></p>
                                    <p><%=SystemProperities.getBookStatusString(bookTemp.getStatus())%></p>
                                    <p><a href="../BookDetail?bookid=<%=bookTemp.getBookId()%>">Xem chi tiết </a> </p>
                                    </div>
                                   </td>
                            <%}%>
                        </tr>
                  </table>


                  </div><!-- end bookmonth -->
             </div><!-- end .col -->
             <div id="whitey"></div>
             <div class="clear">
                 <div class="fix">
                 </div>
             </div>
         </div><!-- end orangerow -->

         <div id="greenrow">
             <%@include file="./subpage/navGreen.jsp" %>
             <div class="col">
                 <p>Sách hay ngẫu nhiên </p>
        <table border="1" id="bookrandom">
        <%if(book != null){%>
            <tr>
                <%
                String imgSrc = book.getImgPath();
                %>
                <td width="84"> <img src=".."<%=imgSrc%> width="79" height="83" alt="HinhAnh" class="left" /></td>
                <td width="58"><p><%=book.getName()%></p>
                    <p><%=book.getBookType()%> </p></td>
                <td width="51"><%=book.getAuthor()%></td>
                <td width="54"><%=book.getPublisher()%></td>
                <td width="92"><%=book.getCounter()%></td>
                <td style="border: none;"><input type="button" value=">>" onclick="nextRandom()"></td>
            </tr>
         <%}%>
     </table>
             </div>
             <div class="clear"></div>
         </div><!-- end greenrow -->

          <%@include file="./subpage/footer.jsp" %>
      </div><!-- end wrapper -->
    </body>
    <script  type = "text/javascript" >
        ////////////////////////////////////
        function createRequestObject(){
            var req;
            if(window.XMLHttpRequest){
                req = new XMLHttpRequest();
            }else if(window.ActiveXObject){
                req = new ActiveXObject("Microsoft.XMLHTTP");
            }else{
                alert('Your browser is not IE 5 or higher, or Firefox or Safari or Opera');
            }
            return req;
        }      
        var http = createRequestObject();
        //////////////////////////////////////

        function nextRandom(){           
            if(http){
                http.open("GET","../HomePage?function=reloadbook",true);
                http.onreadystatechange = handleResponse;
                http.send(null);
            }
        }
        function handleResponse(){
            if(http.readyState == 4 && http.status == 200){
                var detail=document.getElementById("bookrandom");
                detail.innerHTML=http.responseText;
            }
        }
    </script>
</html>
